// Tags:
#include <algorithm>
#include <cstdio>

const int N = 1e2 + 5, lim = 17;
int n, m, srow, scol, ans, bomshfrow, lefshfcol, topshfrow, ritshfcol, rest,
    f[N][N];
char map[N][N];

void solve(int step, int crow, int ccol, int sum) {
  if (sum + rest <= ans) return;
  if (step > lim) return ans = std::max(ans, sum), void();
  char tmp[11];
  int delta = 0;
  if (ccol != 1) {
    if (ccol + ritshfcol <= m)
      for (int i = 1; i <= n; ++i)
        delta += (map[i][ccol + ritshfcol] == 'o'),
            tmp[i] = map[i][ccol + ritshfcol], map[i][ccol + ritshfcol] = '.';
    tmp[10] = map[crow][ccol];
    map[crow][ccol] = '.';
    rest -= delta;
    solve(step + 1, crow, ccol - 1, sum + (map[crow][ccol - 1] == 'o'));
    rest += delta;
    if (ccol + ritshfcol <= m)
      for (int i = 1; i <= n; ++i) map[i][ccol + ritshfcol] = tmp[i];
    map[crow][ccol] = tmp[10];
  }
  delta = 0;
  if (crow != 1) {
    if (crow + bomshfrow <= n)
      for (int i = 1; i <= m; ++i)
        delta += (map[crow + bomshfrow][i] == 'o'),
            tmp[i] = map[crow + bomshfrow][i], map[crow + bomshfrow][i] = '.';
    tmp[10] = map[crow][ccol];
    map[crow][ccol] = '.';
    rest -= delta;
    solve(step + 1, crow - 1, ccol, sum + (map[crow - 1][ccol] == 'o'));
    rest += delta;
    if (crow + bomshfrow <= n)
      for (int i = 1; i <= m; ++i) map[crow + bomshfrow][i] = tmp[i];
    map[crow][ccol] = tmp[10];
  }
  delta = 0;
  if (crow != n) {
    if (crow - topshfrow > 0)
      for (int i = 1; i <= m; ++i)
        delta += (map[crow - topshfrow][i] == 'o'),
            tmp[i] = map[crow - topshfrow][i], map[crow - topshfrow][i] = '.';
    tmp[10] = map[crow][ccol];
    map[crow][ccol] = '.';
    rest -= delta;
    solve(step + 1, crow + 1, ccol, sum + (map[crow + 1][ccol] == 'o'));
    rest += delta;
    if (crow - topshfrow > 0)
      for (int i = 1; i <= m; ++i) map[crow - topshfrow][i] = tmp[i];
    map[crow][ccol] = tmp[10];
  }
  delta = 0;
  if (ccol != m) {
    if (ccol - lefshfcol > 0)
      for (int i = 1; i <= n; ++i)
        delta += (map[i][ccol - lefshfcol] == 'o'),
            tmp[i] = map[i][ccol - lefshfcol], map[i][ccol - lefshfcol] = '.';
    tmp[10] = map[crow][ccol];
    map[crow][ccol] = '.';
    rest -= delta;
    solve(step + 1, crow, ccol + 1, sum + (map[crow][ccol + 1] == 'o'));
    rest += delta;
    if (ccol - lefshfcol > 0)
      for (int i = 1; i <= n; ++i) map[i][ccol - lefshfcol] = tmp[i];
    map[crow][ccol] = tmp[10];
  }
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("C.in", "r", stdin);
  freopen("C.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", map[i] + 1);
    for (int j = 1; j <= m; ++j) {
      if (map[i][j] == 'E')
        srow = i, scol = j, bomshfrow = n - i, topshfrow = i - 1,
        lefshfcol = j - 1, ritshfcol = m - j;
      if (map[i][j] == 'o') ++rest;
    }
  }
  if (srow == 1 && scol == 1) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        f[i][j] = std::max(f[i - 1][j], f[i][j - 1]) + (map[i][j] == 'o');
        ans = std::max(ans, f[i][j]);
      }
    }
  } else {
    solve(1, srow, scol, 0);
  }
  printf("%d", ans);
  return 0;
}